/* v 0.0.2 */
const {version, name} = require("./package");
const fs = require("fs");
const env = process.argv[2] || ""; // dev 调试模式

const indexPath = "./src/index.tsx";
const data = fs.readFileSync(indexPath);
const index = data.toString().replace(/(\/\* @dynamic (.*?) \*\/\n*\n*\r*\s*\t*)(.*?)(\n*\n*\r*\s*\t*\/\* @dynamic end \*\/)/gi, (a, s1, s2, s3, s4) => {
    let code = "";
    switch (s2) {
        case "version":
            code = `window.ParaWeb = {name:'${name}',version: '${version}', env: '${env || ""}', buildTime: '${new Date().toLocaleString()}'}`;
            break;
    }
    return `${s1}${code}${s4}`;
});
try {
    fs.writeFileSync(indexPath, index);
} catch (err) {
    console.log(err);
}
console.log("React Cli Running...");